#include "errorcodes.h"
#include "buildsettings.h"

#ifndef _TREE_
#define _TREE_

typedef struct structTreeNode TreeNode;
typedef struct structTree Tree;
typedef struct structForest Forest;
typedef enum enumTreeNodeValueType TreeNodeValueType;

//! Defines the types associated with the tree node value.
enum enumTreeNodeValueType
{
	TREENODEVALUETYPE_EMPTY,
	TREENODEVALUETYPE_TASK,
	TREENODEVALUETYPE_OTHER
};

//! A tree node.
struct structTreeNode
{
	//! A pointer for extensions
	void *Value;
	//! Type of data in the Value field
	TreeNodeValueType ValueType;
	//! A pointer to the node's parent
	struct structTreeNode *Parent;
	//! A pointer to the next sibling.
	struct structTreeNode *NextSibling;
	//! A pointer to the previous sibling.
	struct structTreeNode *PreviousSibling;
	//! A pointer to the first child in the list of children
	struct structTreeNode *FirstChild;
	//! A pointer to the last child in the list of children
	struct structTreeNode *LastChild;

	void (*Print)(TreeNode *tn, int indent);
};

//! A tree structure.
struct structTree
{
	//! A pointer for extensions
	void *Value;
	//! Root  of the tree
	TreeNode *Root;

	int (*RemoveSubtree)(TreeNode *parent, TreeNode *child);
	int (*InsertChild)(TreeNode *parent, TreeNode *child);
	int (*FreeTreeNode)(TreeNode *n);
	int (*Print)(Tree t);
};

Tree new_Tree();
TreeNode *new_TreeNode();
int destroy_TreeNode(TreeNode *n);

#endif
